<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="com.pojo.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: jason
  Date: 2021/1/28
  Time: 8:33 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--
    遍历1到10，输出
    begin属性设置开始的索引
    end属性设置结束的索引
    var属性表示遍历的变量
--%>
<table>
    <c:forEach begin="1" end="10" var="i" >
        <tr>
            <td>第${ i }行</td>
        </tr>
    </c:forEach>
</table>

<hr>
<%--
    遍历Object数组
    for ( Object : arr )
    items表示遍历的数据源（遍历的集合）
    var表示当前遍历到的数据
--%>
    <%
        request.setAttribute("arr",new String[]{"1231231231","123123123123"});
    %>
    <c:forEach items="${requestScope.arr}" var="item">
        ${item}<br/>
    </c:forEach>

    <%
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("key1","value1");
        map.put("key2","value2");
        map.put("key3","value3");
        request.setAttribute("map",map);
//        for(Map.Entry<String,Object> entry : map.entrySet()){
//
//        }
    %>

    <c:forEach items="${requestScope.map}" var="entry">
        ${entry}
        ${entry.key}
        ${entry.value}}
    </c:forEach>

<%--
    遍历list集合，list里存放Student类
--%>
    <%
        List<Student> studentList = new ArrayList<Student>();
        for (int i=1;i<=10;i++){
            studentList.add(new Student(i,"username"+i,"pass"+i,18+i,"phone"+i));
        }

        request.setAttribute("stus",studentList);
    %>

<table>
    <tr>
        <th>编号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>年龄</th>
        <th>电话</th>
        <th>操作</th>
    </tr>
<%--step属性表示步长值
    begin表示开始遍历的索引
    end表示结束遍历的索引
    varStatus表示当前遍历到的数据的状态
--%>

    <c:forEach items="${requestScope.stus}" begin="2" end="4" varStatus="status" var="stu">
        <tr>
            <td>${stu.id}</td>
            <td>${stu.username}</td>
            <td>${stu.password}</td>
            <td>${stu.age}</td>
            <td>${stu.phone}</td>
            <td>编辑操作</td>
            <td>${status.index}</td>
        </tr>

    </c:forEach>
</table>
</body>
</html>